package cn.conow.pmo.action;

import cn.conow.pmo.entity.Person;
import cn.conow.system.action.BaseAction;
import cn.conow.system.util.BeanUtil;
import cn.conow.system.util.JsonUtil;
import cn.conow.system.util.StringUtil;
import cn.conow.system.web.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * PersonAction层
 * @author dapaer
 * @since v1.0.0
 */
@SuppressWarnings({ "serial" })
@Component
@Scope("prototype")
public class PersonAction extends BaseAction {
	
	@Autowired
	private PersonService personService;
	
	/**
	 * 获取实体信息
	 * @return
	 */
	private Person getEntity(){
		Map map = super.getRequestMap();
		Person entity = new Person();
		BeanUtil.copyProperties(entity, map);
		return entity;
	}



	/**
	 * 通过参数查询
	 * @return
	 */
	public String queryMapByParams(){
		Person entity = getEntity();
		List<Map> lis = personService.queryMapByParams(entity);
		Result result = new Result(lis);
		super.renderToOutput(result);
		return null;
	}


	/**
	 * 通过参数分页查询
	 * @author zhengyiling
	 * @return
	 */
	public String queryPageByParams(){
		Person entity = getEntity();
		personService.queryPageByParams(entity);
		Result result = new Result();
		super.renderToOutput(result);
		return null;
	}


	/**
	 * 通过参数查询实体列表
	 * @author zhengyiling
	 * @return
	 */
	public String queryByParams(){
		Person entity = getEntity();
		personService.queryByParams(entity);
		Result result = new Result();
		super.renderToOutput(result);
		return null;
	}

	/**
	 * 保存或更新实体
	 * @author zhengyiling
	 * @return
	 */
	public String saveOrUpdate(){
		Person entity = getEntity();
		personService.saveOrUpdate(entity);
		Result result = new Result();
		super.renderToOutput(result);
		return null;
	}



	/**
	 * 批量保存或更新
	 * @author zhengyiling
	 * @return
	 */
	public String saveTemp(){
		Person entity = getEntity();
		personService.queryById(entity.getID());
		Result result = new Result();
		super.renderToOutput(result);
		return null;
	}


}
